package com.ad.advertiser.dao.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.dao.DataAccessException;

import com.ad.advertiser.dao.IAdsDAO;
import com.ad.advertiser.entity.Ads;
import com.ad.blogger.dao.FansDAO;
import com.ad.common.dao.BaseDAO;

public class AdsDAOImpl extends BaseDAO implements IAdsDAO {
	private static final Log logger = LogFactory.getLog(FansDAO.class);
	public static final String ID="id" ;
	@Override
	public List<Ads> findAllByUserId(Integer userId) {
		return findByProperty(ID, userId);
	}

	@Override
	public Ads findById(Integer adsId) {
		try {
			return (Ads) this.getHibernateTemplate().get(Ads.class.getName(), adsId);
		} catch (DataAccessException e) {
			logger.error("get failed", e);
			throw e;
		}
	}

	@Override
	public List<Ads> findByProperty(String propertyName, Object propertyValue) {
		logger.debug("findByProperty propertyName="+propertyName+",propertyValue="+propertyValue);
		String hql = "FROM Ads as ads WHERE ads."+propertyName+"= ?" ;
		return this.getHibernateTemplate().find(hql, propertyValue);
	}

	@Override
	public void save(Ads ads) {
		this.getHibernateTemplate().save(ads);
	}

	@Override
	public void saveOrUpdate(Ads ads) {
		try {
			this.getHibernateTemplate().save(ads);
		} catch (DataAccessException e) {
			e.printStackTrace();
			throw e;
		}

	}
public static void main(String[] args){
	System.out.println(Ads.class);
	System.out.println(Ads.class.getName());
	System.out.println(Ads.class.getClass());
}
}
